from aiohttp.web import Application, RouteTableDef, Response, run_app

routes = RouteTableDef()
routes.static("/doc", "./pages")
routes.static("/css", "./css")
routes.static("/font", "./font")
routes.static("/book", "./books")
routes.static("/imgs", "./imgs")

@routes.get("/")
async def homepage(request):
    return Response(text=request.app["homepage"], content_type="text/html")



def gen_app():
    app = Application()
    app.add_routes(routes)
    with open("./index.html", "rb") as f:
        app["homepage"] = f.read().decode()
    return app


def main():
    run_app(gen_app(), port="8081")


if __name__ == "__main__":
    main()
